import request from '@/utils/request'

//新增表单分类
export function addCategory(category) {
  return request({
    url: '/form/category/',
    method: 'post',
    data: category
  })
}

//修改表单分类
export function editCategory(category) {
  return request({
    url: '/form/category/edit',
    method: 'post',
    data: category
  })
}

//删除表单分类
export function delCategory(id) {
  return request({
    url: `/form/category/delete/${id}`,
    method: 'get'
  })
}

//获取表单分类详情
export function getCategory(id) {
  return request({
    url: `/form/category/${id}`,
    method: 'get'
  })
}

//获取所有表单分类
export function getAllCategory() {
  return request({
    url: '/form/category/all',
    method: 'get'
  })
}

//分页获取表单分类
export function getPageCategory(params) {
  return request({
    url: '/form/category/page',
    method: 'get',
    params: params
  })
}

//新增表单信息
export function addFormInfo(form) {
  return request({
    url: '/form/sys/',
    method: 'post',
    data: form
  })
}

//创建表
export function createTable(fields) {
  return request({
    url: '/form/project/createtable',
    method: 'post',
    data: fields
  })
}


//修改数据后删除数据并重新添加，创建表
export function updatatablecolumn(fields) {
  return request({
    url: '/form/project/updatatablecolumn',
    method: 'post',
    data: fields
  })
}

//添加库表字段
export function addField(fields) {
  return request({
    url: '/form/project/addccolumntable',
    method: 'post',
    data: fields
  })
}

//删除库表字段
export function deleteField(fields) {
  return request({
    url: '/form/project/deleteColumntable',
    method: 'post',
    data: fields
  })
}

//修改库表
export function alterTable(fields) {
  return request({
    url: '/form/project/alter-table-st',
    method: 'post',
    data: fields
  })
}

//修改表单信息
export function editFormInfo(form) {
  return request({
    url: '/form/sys/edit',
    method: 'post',
    data: form
  })
}
export function editlist(list) {
    return request({
      url: '/form/sys/editlist',
      method: 'post',
      data: list
    })
  }


//删除表单表
export function delFormInfo(id) {
  return request({
    url: `/form/sys/delete/${id}`,
    method: 'get'
  })
}

//表单编辑时删除子表单表
export function delFormInfoEdit(id) {
  return request({
    url: `/form/sys/deleteChild/${id}`,
    method: 'get'
  })
}

//批量删除
export function multiDel(ids) {
  return request({
    url: `/form/sys/delete`,
    method: 'post',
    data: ids
  })
}

//根据id获取表单表详情
export function getFormInfo(id) {
  return request({
    url: `/form/sys/${id}`,
    method: 'get'
  })
}
//根据id获取表单表按钮详情
export function getBtnInfo(id) {
  return request({
    url: `/system/menu/getsonbuttons?parentId=${id}`,
    method: 'get'
  })
}

//获取formname获取表单表详情
export function getFormExist(name) {
  return request({
    url: `/form/sys/getByFormName/${name}`,
    method: 'get'
  })
}

//分页获取表单表
export function getPageFormInfo(params) {
  return request({
    url: '/form/sys/page',
    method: 'get',
    params: params
  })
}

//启用表单
export function enableForm(id) {
  return request({
    url: `/form/sys/enable/${id}`,
    method: 'get'
  })
}

//禁用表单
export function disableForm(id) {
  return request({
    url: `/form/sys/disable/${id}`,
    method: 'get'
  })
}
//获取业务库所有表名
export function getTableNameListForm() {
  return request({
    url: '/form/project/getTableNameListForm',
    method: 'get'
  })
}


//获取业务库所有表名
export function getTableNames() {
  return request({
    url: '/form/project/getTableNameList',
    method: 'get'
  })
}

export function getTableListExcludeForm(params) {
    return request({
        url: '/form/project/getTableListExcludeForm',
        method: 'get',
        params: params
    })
}


//插入数据
export function insertData(data) {
  return request({
    url: '/form/project/insertdata',
    method: 'post',
    data: data
  })
}

//修改数据
export function updateData(data) {
  return request({
    url: '/form/project/updata',
    method: 'post',
    data: data
  })
}

//获取数据库所有表名
export function getAllTableName() {
  return request({
    url: '/form/project/getTableName',
    method: 'get'
  })
}

//获取所有已发布表单名称
export function getAllFormName() {
  return request({
    url: '/form/sys/selectListRelease',
    method: 'get'
  })
}

// 获取不重复已发布表单名称
// export function getNoRepeatFormName(params) {
//   return request({
//     url: '/form/sys/selectListReleaseByEncode',
//     method: 'get',
//     params: params
//   })
// }

// 获取不重复已发布表单名称---新的从数据源获取
export function getNoRepeatFormName(params) {
  return request({
    url: '/infra/source/listchooseByExcludeId',
    method: 'get',
    params: params
  })
}

// 获取已发布表单中所有字段
export function getFieldNameList(params) {
  return request({
    url: '/form/sys/getFieldNameList',
    method: 'get',
    params: params
  })
}

//获取所有表单名称
export function getAllForm() {
  return request({
    url: '/form/sys/selectListAll',
    method: 'get'
  })
}

//获取表中所有字段
export function getTableColumn(data) {
  return request({
    url: '/form/project/getColumn',
    method: 'get',
    params: data
  })
}

//获取表中某字段数据
export function getColumnData(data) {
  return request({
    url: '/form/project/getData',
    method: 'post',
    data: data
  })
}

//获取字典类型列表
export function getDictName() {
  return request({
    url: '/system/dict-type/list-simple',
    method: 'post',
    data: { status: 0 }
  })
}

//获取字典数据
export function getDictData(data) {
  return request({
    url: '/system/dict-data/getListByDictType',
    method: 'get',
    params: data
  })
}

// //手写签名，传参图片，并返回url
// export function getImgUrl(data) {
//   return request({
//     url: '/form/project/fileUploadBase64',
//     method: 'post',
//     data: data,
//   })
// }

//手写签名，传参图片，并返回url
export function getImgUrl(data) {
  return request({
    url: '/infra/file/upload',
    method: 'post',
    data: data,
  })
}

//表单规则
export function getFormRule(data) {
  return request({
    url: '/form/project/formFieldRules',
    method: 'post',
    data: data
  })
}

// 批量查用户信息
export function getUserList(data) {
    return request({
        url: '/form/category/getUserList',
        method: 'post',
        data: data
    })
}

// 表结构配置 子表单 批量创建
export function createtablelist(data) {
    return request({
        url: '/form/project/createtablelist',
        method: 'post',
        data: data
    })
}

// 批量查岗位
export function gePostList(data) {
    return request({
        url: '/form/category/gePostList',
        method: 'post',
        data: data
    })
}

// 创建表关系(主表与子表单的关系)
export function savelist(data) {
    return request({
        url: '/form/sys/savelist',
        method: 'post',
        data: data
    })
}

// 批量查部门
export function geDeptList(data) {
    return request({
        url: '/form/category/geDeptList',
        method: 'post',
        data: data
    })
}

// 提交数据(填报数据适配子表单)
export function insertdatalist(data) {
    return request({
        url: '/form/project/insertdatalist',
        method: 'post',
        data: data
    })
}

// 查询数据源
export function getDataSelect(params) {
    return request({
        url: `/form/project/getDataSelect`,
        method: 'post',
        data: params
    })
}

//根据id获取管理页面和纯表单是否被删除
export function getDelStatus(params) {
  return request({
    url: `/system/menu/get`,
    method: 'get',
    params:params
  })
}
// 级联组件
export function getCascadeData(params) {
    return request({
        url: `/form/project/getCascadeData`,
        method: 'post',
        data: params
    })
}
// 根据tableId获取字段信息   子表单--默认值 --值来源
export function getMdColumnsByTableIdUsingGET(tableId) {
  return request({
      url: `/form/columns/${tableId}/get`,
      method: 'get',
  })
}

//获取所有表单分类
export function getAllExternal() {
  return request({
    url: '/bpm/form/external/list',
    method: 'get'
  })
}
// 查询表单链接
export function getEditUrl(params) {
  return request({
    url: '/form/sys/edit',
    method: 'post',
    data:params
  })
}

//获取表中所有字段
export function getTableFont(data) {
  return request({
    url: '/bpm/form/columns',
    method: 'get',
    params: data
  })
}

// 获取数据源库表数据
export function listchoose() {
    return request({
      url: '/infra/source/listchoose',
      method: 'get',
    })
}

// 根据库表id获取数据库字段数据
export function sourceTestList(id) {
    return request({
      url: '/infra/rdb/execute/sourceTestList?id=' + id,
      method: 'get',
    })
}
//清空删除数据
export function deleteAllField(fields) {
  return request({
    url: '/form/sys/deleteChildList',
    method: 'post',
    data: fields
  })
}
